import basegraphunit from './basegraphunit.js'
import coorPkg from '../../struct/coord.js'
import fillinfo from '../fillinfo.js';
import { LGXEnums } from '../../sysenum.js';

class Cylinder extends basegraphunit.BaseGraphUnit {
    constructor() {
        super();
        this.pos = new coorPkg.PointPos();
        this.x = 0;
        this.y = 0;
        this.angle = 0;
        this.width = 0;
        this.height = 0;
        this.arcRadius = 0;
        this.coverFillDef = null;
        this.coverFillMode = LGXEnums.LGXFillStyle.SOLID;
    }
    translateSubInfo(tx,ty){
        this.x += tx;
        this.y += ty;
    }

    toJson() {
        var jsonobj = {};
        super.toJson(jsonobj);
        jsonobj["x"] = this.x;
        jsonobj["y"] = this.y;
        jsonobj["width"] = this.width;
        jsonobj["height"] = this.height;
        jsonobj["arcRadius"] = this.arcRadius;
        jsonobj["coverFillMode"] = this.coverFillMode;
        if (this.coverFillDef){
            jsonobj["coverFillDef"] = this.coverFillDef.toJson();
        }
        return jsonobj;
    }
    fromJson(obj) {
        super.fromJson(obj);
        this.x = obj["x"];
        this.y = obj["y"];
        this.width = obj["width"];
        this.height = obj["height"];
        this.arcRadius = obj["arcRadius"];
        this.pos.x = this.x;
        this.pos.y = this.y;
        this.coverFillMode = obj["coverFillMode"];
        if (!this.coverFillMode){
            this.coverFillMode = LGXEnums.LGXFillStyle.SOLID;
        }
        let tmp = obj["coverFillDef"];
        if (tmp){
            this.coverFillDef = new fillinfo.LGXFillDefInfo();
            this.coverFillDef.fromJson(tmp);
            this.coverFillDef.fillStyle = this.coverFillMode;
        }
        
    }

    cloneCopy() {
        var pNewInfo = new Cylinder();
        super.cloneCopy(pNewInfo);
        pNewInfo.x = this.x;
        pNewInfo.y = this.y;
        pNewInfo.width = this.width;
        pNewInfo.height = this.height;
        pNewInfo.arcRadius = this.arcRadius;
        pNewInfo.coverFillMode = this.coverFillMode;
        if (this.coverFillDef){
            pNewInfo.coverFillDef = new fillinfo.LGXFillDefInfo();
            pNewInfo.coverFillDef.clone(this.coverFillDef);
        }
        return pNewInfo;
    }
}

export default { Cylinder }